package lifeOfAFish;

import lifeOfAFish.scenegraph.*;
import lifeOfAFish.scenegraph.geom.*;

import javax.media.opengl.*;
/**
 * This is class maintains the entire scene
 * @author Erik Bonner
 *
 */
public class Scene extends Entity {

	private FishTank m_tank;
	private sgCamera[] m_camera;
	private int m_currCam;
	private static final int NumCams = 6;
	private float[] m_viewingAngle = new float[NumCams];
	private static final int FishCamIndex = 5; 
	
	private sgLight m_pianoLight;
	private sgLight m_dayLight; 
	private sgLight m_billardLight;
	
	private static final int NumFTLights = 1;
	public sgLight[] m_ftLight = new sgLight[NumFTLights];
	
	private sgGeomCube m_ftBulb = new sgGeomCube(0.3f);
	sgGeomCube pole  = new sgGeomCube();;
	private sgMaterial m_mtlBulbDay;
	private sgMaterial m_mtlBulbNight;
	
	private boolean m_day = true;
	
	
	private int m_candleCount = 0;
	private int m_flickerTime = 10;
	private float m_candleIntensity = 1.0f;
	
	private float[] plAmbient = {0.6f, 0.3f, 0.0f, 1.0f};
	private float[] plDiffuse = {0.6f, 0.0f, 0.0f, 1.0f};
	private float[] plSpecular = {0.6f, 0.3f, 0.0f, 1.0f};
	
//	private float[] blAmbient = {1.0f, 1.0f, 1.0f, 1.0f};
//	private float[] blDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
//	private float[] blSpecular = {0.1f, 0.1f, 0.1f, 1.0f};
	private float[] blAmbient = {0.6f, 0.6f, 0.5f, 1.0f};
	private float[] blDiffuse = {0.6f, 0.6f, 0.5f, 1.0f};
	private float[] blSpecular = {0.1f, 0.1f, 0.1f, 1.0f};
	
	private float[] ftAmbientBlue = {0.1f, 0.1f, 0.8f, 1.0f};
	private float[] ftDiffuseBlue = {0.1f, 0.1f, 0.8f, 1.0f};
	private float[] ftSpecularBlue = {0.0f, 0.0f, 0.1f, 1.0f};
	
	private float[] ftAmbientGreen = {0.1f, 0.8f, 0.1f, 1.0f};
	private float[] ftDiffuseGreen = {0.1f, 0.8f, 0.1f, 1.0f};
	private float[] ftSpecularGreen = {0.1f, 0.5f, 0.1f, 1.0f};
	
	private boolean test = false;
	sgTransform rot = new sgTransform();

	
	/**
	 * constructor
	 */
	public Scene()
	{
	}
	
	/**
	 * Set the static camera view
	 */
	public void setView(int view)
	{
		view-=1;
		if (view < NumCams && view >= 0){
			m_currCam = view;
			
			if(m_currCam == 2) this.hideLamp();
			else this.showLamp();
		}
		
		sgGeomBlender.getInstance().setCam(m_camera[m_currCam]);
	}
	/**
	 * Get the viewing angle (zoom) for the camera
	 * @return viewing angle
	 */
	public float getViewingAngle()
	{
		return m_viewingAngle[m_currCam];
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

	/**
	 * Set OpenGL settings
	 */
	public void configureGL()
	{
		GL gl = sgGlobals.gl;
		
	}
	
	public void setDay()
	{
		System.out.println("setDay()");
		m_dayLight.setIntensity(1.0f);
		m_pianoLight.setIntensity(0.0f);
		m_ftLight[0].setIntensity(0.0f);
		m_ftBulb.setMaterial(m_mtlBulbDay);
		
		m_day = true;
	}
	
	public void setNight()
	{
		System.out.println("setNight");
		m_dayLight.setIntensity(0.0f);
		m_pianoLight.setIntensity(1.0f);
		m_ftLight[0].setIntensity(1.0f);
		m_ftBulb.setMaterial(m_mtlBulbNight);
		
		m_day = false;
	}
	
	public void hideLamp(){
		m_ftBulb.setActive(false);
		pole.setActive(false);
	}
	public void showLamp(){
		m_ftBulb.setActive(true);
		pole.setActive(true);
	}
	
	/**
	 * Do all initialising prior to simulation
	 */
	public void init() {
		GL gl = sgGlobals.gl;
		m_tank = new FishTank();
		m_camera = new sgCamera[NumCams];
		m_currCam = 0;
		float height = 4.0f;
		
		rot.rotate(0.0f, 0.0f, 0.0f, 1.0f);
		
		sgTransform rootTrans = new sgTransform(); 
		rootTrans.translate(-5.0f, 0.0f, 5.0f);
//		rootTrans.translate(0.0f, 0.0f, 0.0f);
		m_node.addChild(rootTrans);
		
		sgVec3[] at = new sgVec3[NumCams];
		at[0] = new sgVec3(2.2f, 1.5f, 2.0f);
		at[1] = new sgVec3(2.0f, 1.1f, 3.0f);
		at[2] = new sgVec3(2.4f, 0.0f, 2.9f);
		at[3] = new sgVec3(1.0f, 0.8f, 0.0f);
		
		at[4] = new sgVec3(0.0f, 0.0f, 0.0f);
		at[5] = new sgVec3(0.0f, 100.0f, 0.0f);
		
		sgVec3 up[] = new sgVec3[NumCams];
		up[0] = new sgVec3(0.0f, 1.0f, 0.0f);
		up[1] = new sgVec3(0.0f, 1.0f, 0.0f);
		up[2] = new sgVec3(0.0f, 0.0f, -1.0f);
		up[3] = new sgVec3(0.0f, 1.0f, 0.0f);
		
		up[4] = new sgVec3(0.0f, 1.0f, 0.0f);
		up[5] = new sgVec3(0.0f, 1.0f, 0.0f);
		
		sgVec3[] eye = new sgVec3[NumCams];
		eye[0] = new sgVec3(2.2f, 3.0f, -0.3f);
		eye[1] = new sgVec3(-1.5f, 2.5f, 3.0f);
		eye[2] = new sgVec3(2.4f, 4.0f, 2.9f);
		eye[3] = new sgVec3(4.8f, height/2.0f, -4.8f);
		
		eye[4] = new sgVec3(0.0f, 0.0f, -1.0f);
		eye[5] = new sgVec3(0.0f, 100.0f, 1.5f);
		
		m_viewingAngle[0] = 45.0f;
		m_viewingAngle[1] = 58.0f;
		m_viewingAngle[2] = 60.0f;
		m_viewingAngle[3] = 60.0f;
		m_viewingAngle[4] = 60.0f;
		m_viewingAngle[5] = 60.0f;
		for (int i = 0; i < NumCams; i++){
			m_camera[i] = new sgCamera();
			m_camera[i].lookAt(at[i], eye[i], up[i]);
		}
		setView(m_currCam+1);
		
		// init the day light
		m_dayLight = sgLightFactory.newLight();
		
		float[] dlPos = {0.0f, 0.0f, 0.0f, 0.0f};
		float[] dlAmbient = {1.0f, 1.0f, 1.0f, 1.0f};
		float[] dlDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
		float[] dlSpecular = {1.0f, 1.0f, 0.0f, 1.0f};
//		float[] dlAmbient = {0.1f, 0.1f, 0.1f, 1.0f};
//		float[] dlDiffuse = {0.1f, 0.1f, 0.1f, 0.1f};
//		float[] dlSpecular = {0.1f, 0.1f, 0.1f, 1.0f};
		
		
		m_dayLight.setPosition(dlPos);
		m_dayLight.setAmbient(dlAmbient);
		m_dayLight.setDiffuse(dlDiffuse);
		m_dayLight.setSpecular(dlSpecular);
		
		sgTransform dlTrans = new sgTransform();
		dlTrans.translate(5.0f, height/2.0f, -5.0f);
		dlTrans.addChild(m_dayLight);
		rootTrans.addChild(dlTrans);
		
		// the fish tank 
		sgTransform aqPos = new sgTransform();
		aqPos.translate(5.5f, 0.805f, -1.0f);
		aqPos.addChild(m_tank.getNode());
		rootTrans.addChild(aqPos);
		
		// the fish tank lights
		float[] ftPos = {0.0f, 0.0f, 0.0f, 1.0f};
		for(int i = 0; i < m_ftLight.length; i++){
			m_ftLight[i] = sgLightFactory.newLight();
			m_ftLight[i].setPosition(ftPos);
			m_ftLight[i].setAmbient(ftAmbientGreen);
			m_ftLight[i].setDiffuse(ftDiffuseGreen);
			m_ftLight[i].setSpecular(ftSpecularGreen);
		}
//		for(int i = m_ftLight.length/2; i < m_ftLight.length; i++){
//			m_ftLight[i] = sgLightFactory.newLight();
//			m_ftLight[i].setPosition(ftPos);
//			m_ftLight[i].setAmbient(ftAmbientGreen);
//			m_ftLight[i].setDiffuse(ftDiffuseGreen);
//			m_ftLight[i].setSpecular(ftDiffuseGreen);
//		}
		
		// position the tank lights
		sgVec3[] ftlPos = new sgVec3[NumFTLights];
		sgVec3[] ftlAt = new sgVec3[NumFTLights];
		ftlPos[0] = new sgVec3(7.5f, 3.0f, -2.0f);
		ftlAt[0] = new sgVec3(7.5f, 1.0f, -2.0f);
		
//		ftlPos[1] = new sgVec3(9.0f, 2.0f, -1.0f);
//		ftlAt[1] = new sgVec3(7.9f, 1.0f, -2.0f);
//		
//		ftlPos[2] = new sgVec3(5.5f, 2.0f, -1.0f);
//		ftlAt[2] = new sgVec3(6.9f, 1.0f, -2.0f);
		
		sgTransform[] ftlTrans = new sgTransform[NumFTLights];
		for(int i = 0; i < m_ftLight.length; i++){
			
			m_ftLight[i].setSpotCutoff(180.0f);
			m_ftLight[i].setSpotDir(sgVec3.subtract(ftlAt[i], ftlPos[i]).getV());
			
			ftlTrans[i] = new sgTransform();
			ftlTrans[i].translate(ftlPos[i].getV());
			
			ftlTrans[i].addChild(m_ftLight[i]);
			rot.addChild(ftlTrans[i]);
//			rootTrans.addChild(ftlTrans[i]);
			rootTrans.addChild(rot);
		}
		
		sgTransform sphereTrans = new sgTransform();
		sphereTrans.translate(ftlPos[0].getV());
		rootTrans.addChild(sphereTrans);
		sphere1 = new sgGeomCube(0.25f);
		mat = new sgMaterial();
		mat.setAmbient(0.1f, 1.0f, 0.0f, 1.0f);
		mat.setDiffuse(1.0f, 1.0f, 0.0f, 1.0f);
		mat.setSpecular(0.0f, 1.0f, 0.0f, 1.0f);
		mat.setEmission(0.0f, 1.0f, 0.1f, 1.0f);
		sphere1.setMaterial(mat);
		sphere1.setName("Sphere_1");
//		sphereTrans.addChild(sphere1);
		
		// attach the bulb to the wall
		sgTransform poleScale = new sgTransform();
		poleScale.scale(0.10f, 0.10f, 1.9f);
		
		sgTransform ftLightRoot = new sgTransform();
		ftLightRoot.translate(7.5f, 3.0f, -0.9f);
		
//		pole.loadTexture("models/textures/wood01.jpg");
		poleScale.addChild(pole);
		ftLightRoot.addChild(poleScale);
		rootTrans.addChild(ftLightRoot);
		
		sgMaterial poleMat = new sgMaterial();
		poleMat.setAmbient(0.0f, 0.0f, 0.0f, 1.0f);
		poleMat.setDiffuse(0.3f, 0.3f, 0.3f, 1.0f);
		poleMat.setSpecular(0.0f, 0.0f, 0.0f, 1.0f);
		pole.setMaterial(poleMat);
		
		m_mtlBulbDay = new sgMaterial();
		m_mtlBulbDay.setAmbient(0.1f, 0.6f, 0.1f, 0.3f);
		m_mtlBulbDay.setDiffuse(0.1f, 0.6f, 0.1f, 0.3f);
		m_mtlBulbDay.setSpecular(0.0f, 1.0f, 0.0f, 0.3f);
		
		m_mtlBulbNight = new sgMaterial();
		m_mtlBulbNight.setAmbient(0.1f, 0.8f, 0.1f, 1.0f);
		m_mtlBulbNight.setDiffuse(0.1f, 0.8f, 0.1f, 1.0f);
		m_mtlBulbNight.setSpecular(0.0f, 0.8f, 0.0f, 1.0f);
		m_mtlBulbNight.setEmission(0.0f, 1.0f, 0.1f, 1.0f);
		
		sphereTrans.addChild(m_ftBulb);
		m_ftBulb.setMaterial(m_mtlBulbDay);
		m_ftBulb.setOpaque(false);
		
//		m_mtlBulbNight;
		
		// add the bed 
		float[] origin = {0.0f, 0.0f, 0.0f};
		float[] sourceBed = {8.0f, 0.0f, -6.75f};
		sgMaterial bedMat = new sgMaterial();
		bedMat.setAmbient(0.5f, 0.1f, 0.1f, 1.0f);
		bedMat.setDiffuse(0.4f, 0.0f, 0.0f, 1.0f);
		bedMat.setSpecular(0.0f, 0.0f, 0.0f, 1.0f);
		
		sgTransform bedTrans = new sgTransform();
		bedTrans.translate(sourceBed);
		sgTransform bedScale = new sgTransform(); float bs = 0.065f;
		bedScale.scale(bs, bs, bs);
		sgTransform bedRot = new sgTransform();
		bedRot.rotate(-90.0f, 0.0f, 1.0f, 0.0f);
		bedTrans.addChild(bedRot);
		bedRot.addChild(bedScale);
//		sgGeomCuboid bed = new sgGeomCuboid(origin, 2.25f, 0.4f, 2.25f);
//		bed.setMaterial(bedMat);
		sgGeomModel bed = new sgGeomModel();
		bed.setOBJFileName("models/bed/bed.obj");
		bed.load();
		bed.setMaterial(bedMat);
		bedScale.addChild(bed);
		rootTrans.addChild(bedTrans);
		
		
		// add the billiard table
		float[] sourceBillard = {2.0f, 0.0f, -6.68f};
		sgMaterial billardMat = new sgMaterial();
		billardMat.setAmbient(0.1f, 0.3f, 0.1f, 1.0f);
		billardMat.setDiffuse(0.0f, 0.3f, 0.0f, 1.0f);
		billardMat.setSpecular(0.0f, 0.0f, 0.0f, 1.0f);
		
		sgTransform billardTrans = new sgTransform();
		billardTrans.translate(sourceBillard);
		sgTransform billardScale = new sgTransform();
		float s = 0.045f;
		billardScale.scale(s, s, s);
		sgTransform billardRot = new sgTransform();
		billardRot.rotate(90.0f, 0.0f, 1.0f, 0.0f);
		
		sgGeomModel billard = new sgGeomModel();
		billard.setOBJFileName("models/billard/billard_fixed.obj");
		billard.load();
		
		billard.setMaterial(billardMat);
		billardTrans.addChild(billardRot);
		billardRot.addChild(billardScale);
		billardScale.addChild(billard);
		rootTrans.addChild(billardTrans);
		
		// set up the billard light source
		float[] blPos = {0.0f, 0.0f, 0.0f, 1.0f};
		float[] bAtt = {1.5f, 0.5f, 1.0f};
		m_billardLight = sgLightFactory.newLight();
		m_billardLight.setPosition(blPos);
		m_billardLight.setAmbient(blAmbient);
		m_billardLight.setDiffuse(blDiffuse);
		m_billardLight.setSpecular(blSpecular);
		m_billardLight.setAttenuation(bAtt);
		sgTransform blTrans = new sgTransform();
		blTrans.translate(2.0f, 1.9f, -6.8f);
		blTrans.addChild(m_billardLight);
		rootTrans.addChild(blTrans);
		
	
		
		
		// add the piano
		float[] sourcePiano = {2.5f, 0.0f, -2.0f};
		sgMaterial pianoMat = new sgMaterial();
		pianoMat.setAmbient(0.1f, 0.1f, 0.1f, 1.0f);
		pianoMat.setDiffuse(0.1f, 0.1f, 0.1f, 1.0f);
		pianoMat.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);

		sgTransform pianoTrans = new sgTransform();
		pianoTrans.translate(sourcePiano);
		sgTransform pianoRot = new sgTransform();
		pianoRot.rotate(40.0f, 0.0f, 1.0f, 0.0f);
		pianoTrans.addChild(pianoRot);
		
		sgGeomModel piano = new sgGeomModel();
		piano.setOBJFileName("models/piano/Piano_optimized.obj");
//		piano.setMaterial(pianoMat);
		pianoRot.addChild(piano);
		rootTrans.addChild(pianoTrans);
		piano.load();
		
		// piano light
		float[] plPos = {0.0f, 0.0f, 0.0f, 1.0f};
		float[] att = {1.5f, 0.5f, 1.0f};
		m_pianoLight = sgLightFactory.newLight();
		m_pianoLight.setPosition(plPos);
		m_pianoLight.setAmbient(plAmbient);
		m_pianoLight.setDiffuse(plDiffuse);
		m_pianoLight.setSpecular(plSpecular);
//		m_pianoLight.setAttenuation(att);
		sgTransform plTrans = new sgTransform();
		plTrans.translate(2.7f, 1.8f, -1.4f);
		plTrans.addChild(m_pianoLight);
		rootTrans.addChild(plTrans);
		
		
		// table
		float[] sourceTable = {1.9f+5.375f, 0.4f, -1.1f-0.875f};
		sgMaterial matTable = new sgMaterial();
		matTable.setAmbient(0.5f, 0.1f, 0.1f, 1.0f);
		matTable.setDiffuse(0.4f, 0.0f, 0.0f, 1.0f);
		matTable.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);

		sgTransform tableTrans = new sgTransform();
		tableTrans.translate(sourceTable);
		sgTransform tableRot = new sgTransform();
		tableRot.rotate(90.0f, 0.0f, 1.0f, 0.0f);
		sgGeomCube table = new sgGeomCube(1.0f);
		sgTransform tableScale = new sgTransform();
		tableScale.scale(2.25f, 0.8f, 3.75f);
		table.setMaterial(matTable);
		table.loadTexture("models/textures/marble01.jpg");
		tableTrans.addChild(tableRot);
		tableScale.addChild(table);
		tableRot.addChild(tableScale);
		rootTrans.addChild(tableTrans);
		
		// create floor
		sgTransform floorTrans = new sgTransform();
		floorTrans.translate(0.0f, 0.0f, -10.0f);
		sgGeomRectXZ floor = new sgGeomRectXZ(0.0f, 10.0f, 0.0f, 10.0f);
		sgMaterial matFloor = new sgMaterial();
		matFloor.setAmbient(0.8f, 0.8f, 0.9f, 1.0f);
		matFloor.setDiffuse(0.8f, 0.8f, 0.9f, 1.0f);
		matFloor.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		floor.loadTexture("models/textures/marble01.jpg");
		floorTrans.addChild(floor);
		rootTrans.addChild(floorTrans);
		
		// create roof
		sgTransform roofTrans = new sgTransform();
		roofTrans.translate(0.0f, height, -10.0f);
		sgGeomRectXZ roof = new sgGeomRectXZ(0.0f, 10.0f, 0.0f, 10.0f);
		roof.loadTexture("models/textures/plaster01.jpg");
		roofTrans.addChild(roof);
		rootTrans.addChild(roofTrans);
		
		String wallTexture = "models/textures/wood01.jpg";
		
		sgGeomRectYZ westWall = new sgGeomRectYZ(0.0f, height, 0.0f, 10.0f);
		sgTransform wwTrans = new sgTransform(); wwTrans.translate(0.0f, 0.0f, -10.0f);
		westWall.loadTexture(wallTexture);
		wwTrans.addChild(westWall);
		rootTrans.addChild(wwTrans);
		
		sgGeomRectYZ eastWall = new sgGeomRectYZ(0.0f, height, 0.0f, 10.0f);
		sgTransform ewTrans = new sgTransform(); ewTrans.translate(10.0f, 0.0f, -10.0f);
		eastWall.loadTexture(wallTexture);
		ewTrans.addChild(eastWall);
		rootTrans.addChild(ewTrans);
		
		sgGeomRectXY southWall = new sgGeomRectXY(0.0f, 10.0f, 0.0f, height);
		southWall.loadTexture(wallTexture);
		rootTrans.addChild(southWall);
		
		sgGeomRectXY northWall = new sgGeomRectXY(0.0f, 10.0f, 0.0f, height);
		sgTransform nwTrans = new sgTransform(); nwTrans.translate(0.0f, 0.0f, -10.0f);
		nwTrans.addChild(northWall);
		northWall.loadTexture(wallTexture);
		rootTrans.addChild(nwTrans);
		
//		sgMaterial wallMat = new sgMaterial();
//		wallMat.setAmbient(0.1f, 0.0f, 0.0f, 1.0f);
//		wallMat.setDiffuse(1.0f, 1.0f, 1.0f, 1.0f);
//		wallMat.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		
		floor.loadTexture("models/textures/marble01.jpg");
		floor.setMaterial(matFloor);
		floorTrans.addChild(floor);
		rootTrans.addChild(floorTrans);
		
		// set necessary openGL properties
		gl.glEnable(GL.GL_TEXTURE_2D);
//		gl.glEnable(GL.GL_CULL_FACE);
		
		if(test) initTest();
		this.setDay();
		
		
		
	}

	/**
	 * This is where the main simulation takes place.
	 * Should be called in a draw method in main simulation loop
	 */
	public void update() {
		GL gl = sgGlobals.gl;
		
		// update the current time
		TimeManager.getInstance().update();
		
		// take care of the candle light
		m_candleCount++;
		if (m_candleCount >= m_flickerTime){
			m_candleCount = 0;
			m_flickerTime = 10+(int)(Math.random()*5.0f);
			m_candleIntensity = 0.5f+(float)(0.5f*Math.random());
			
			
			float[] a = {m_candleIntensity*plAmbient[0], m_candleIntensity*plAmbient[1], m_candleIntensity*plAmbient[2], 1.0f};
			m_pianoLight.setAmbient(a);
			
			float[] d = {m_candleIntensity*plDiffuse[0], m_candleIntensity*plDiffuse[1], m_candleIntensity*plDiffuse[2], 1.0f};; 
			m_pianoLight.setDiffuse(d);
			
			float[] s = {m_candleIntensity*plSpecular[0], m_candleIntensity*plSpecular[1], m_candleIntensity*plSpecular[2], 1.0f};; 
			m_pianoLight.setDiffuse(s);
			
		}
		
		// if we have dawn
		float i = 0.0f;
		if ((TimeManager.getInstance().dawnIntensity()) > 0.0f){
			i = TimeManager.getInstance().dawnIntensity();
		}
		else if ((i = TimeManager.getInstance().duskIntensity()) > 0.0f){
			i = (1.0f - TimeManager.getInstance().duskIntensity());
		}
		
		// apply the transition
		if (i != 0.0f){
			if (i < 0.3f) {
				m_ftBulb.setMaterial(m_mtlBulbNight);
				m_ftLight[0].setIntensity(1.0f);
			}
			else{
				m_ftBulb.setMaterial(m_mtlBulbDay);
				m_ftLight[0].setIntensity(0.0f);
			}
			m_dayLight.setIntensity(i);
			m_pianoLight.setIntensity(1-i);
			
		}
		
//		theta += 0.25*step;
//		rot.rotate(theta, 0.0f, 0.0f, 1.0f);
//		System.out.println(theta);
		
		// Updating Objects
		m_tank.update();
		
		// display scene from preset camera
		if(m_currCam == FishCamIndex){
			m_tank.fishCam(m_camera[m_currCam]);
		}
	    m_camera[m_currCam].apply();
	    
		// draw the scene (solid objects)
		m_node.traverse();
		
		// draw the transparent objects
		sgGeomBlender.getInstance().render();
		if(test) drawTest(gl);
	}
	
	
	
	private sgGeomCube sphere1;
	private sgGeomSphere sphere2;
	private sgTransform rotate;
	private sgTransform rotate2;
	sgMaterial mat;
	private sgCamera testCam;
	
	sgMaterial matTrans;
	sgGeomCube frontCube;
	
	public float theta = 0.0f;
	private float step = 1.0f;
	
	public void initTest(){
		// place the two light sources in the scene, toghether with representative spheres
		rotate = new sgTransform();
		sgTransform trans1 = new sgTransform();
		sgTransform trans2 = new sgTransform();
		trans1.translate(-4.0f, 2.0f, 0.0f);
		trans2.translate(4.0f, 2.0f, 0.0f);
		
		float[] plPos = {0.0f, 0.0f, 0.0f, 1.0f};
		float[] plAmbient = {0.6f, 0.0f, 0.0f, 1.0f};
		float[] plDiffuse = {0.6f, 0.0f, 0.0f, 1.0f};
		float[] plSpecular = {0.0f, 0.0f, 0.0f, 1.0f};
		
		sgLight light1 = sgLightFactory.newLight();
		float[] lpos = {0.0f, 0.0f, 0.0f, 1.0f}; 
		light1.setPosition(lpos);
		light1.setAmbient(plAmbient);
		light1.setDiffuse(plDiffuse);
		light1.setSpecular(plSpecular);
		float[] att = {1.0f, 0.3f, 0.09f};
		light1.setAttenuation(att);
		
//		sgLight light2 = sgLightFactory.newLight();
//		light2.setPosition(lpos);
//		light2.setAttenuation(att);
		
		sphere1 = new sgGeomCube(0.5f);
		mat = new sgMaterial();
		mat.setAmbient(1.0f, 1.0f, 1.0f, 1.0f);
		mat.setDiffuse(1.0f, 1.0f, 1.0f, 1.0f);
		mat.setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
		mat.setEmission(0.0f, 1.0f, 1.0f, 1.0f);
		sphere1.setMaterial(mat);
		sphere1.setName("Sphere_1");
		sphere1.setOpaque(false);
		
		
		sphere2 = new sgGeomSphere(0.25f);
		sphere2.setMaterial(mat);
		sphere2.setName("Sphere_2");
		sphere2.setOpaque(false);
		
		rotate2 = new sgTransform();
		sgTransform trans3 = new sgTransform();
		trans3.translate(0.0f, 0.0f, 1.0f);
		
		testCam = new sgCamera();
		
		m_node.addChild(rotate);
		rotate.addChild(trans1);
		rotate.addChild(trans2);
		trans1.addChild(light1);
		trans1.addChild(sphere1);
//		rotate2.addChild(trans3);
//		trans3.addChild(sphere1);
//		trans2.addChild(light2);
		trans2.addChild(sphere2);
		
	}
	private static boolean flag = true;
	private void drawTest(GL gl)
	{
		theta += step;
		rotate.rotate(theta, 0.0f, 1.0f, 0.0f);
		rotate2.rotate(theta, 1.0f, 0.0f, 0.0f);
		
//		// get the gobal bounding box
//		sgVec3[] verts = sphere1.getGlobalBoundingBox();
//		for (int i = 0; i < 8; i++)
//		{
//			gl.glPushMatrix();
//			gl.glTranslatef(verts[i].getX(), verts[i].getY(), verts[i].getZ());
//			sgGlobals.glut.glutSolidSphere(0.1, 10, 10);
//			gl.glPopMatrix();
//		}
//		
//		verts = sphere2.getGlobalBoundingBox();
//		for (int i = 0; i < 8; i++)
//		{
//			gl.glPushMatrix();
//			gl.glTranslatef(verts[i].getX(), verts[i].getY(), verts[i].getZ());
//			sgGlobals.glut.glutSolidSphere(0.1, 10, 10);
//			gl.glPopMatrix();
//		}

		
	}

}
